local hx__kongcheng_mu = fk.CreateSkill {
  name = "hx__kongcheng_mu",
  tags = { Skill.Compulsory, },
}


hx__kongcheng_mu:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hx__kongcheng_mu.name) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getCardsByArea(Player.Hand,player,true)
    player:addToPile("$hx__kongcheng_mu", cards, false, hx__kongcheng_mu.name)
  end,
})
hx__kongcheng_mu:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hx__kongcheng_mu.name) then
      return #player:getPile("$hx__kongcheng_mu") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCardTo(player:getPile("$hx__kongcheng_mu"), Card.DiscardPile, player, fk.ReasonJustMove, hx__kongcheng_mu.name, nil, true, player)
  end,
})
hx__kongcheng_mu:addEffect(fk.TargetConfirming, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hx__kongcheng_mu.name) then
      return data.from ~= player and #player:getPile("$hx__kongcheng_mu") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"hx__kongcheng_mu_basic","hx__kongcheng_mu_trick","hx__kongcheng_mu_equip"}
    local tos = data.from
    local yes = room:askToChoices(tos,{
      choices = choices,
      min_num = 0,
      max_num = 3,
      skill_name = hx__kongcheng_mu.name,
      prompt = "请猜测观星牌中是否有对应类型的牌：",
      cancelable = false,
    })
    for _, value in ipairs(yes) do
      table.removeOne(choices, value)
    end
    local right = 0
    for _, id in ipairs(player:getPile("$hx__kongcheng_mu")) do
      local str = "hx__kongcheng_mu_"..Fk:getCardById(id):getTypeString()
      if table.contains(yes, str) then
        right = right + 1
        table.removeOne(yes, str)
      else
        table.removeOne(choices, str)
      end
    end
    right = right + #choices
    room:doBroadcastNotify("ShowToast", "猜对了"..right.."项")
    if right < 2 then
      room:doBroadcastNotify("ShowToast", "正确项小于2，"..Fk:translate(player.general).."摸了1张牌")
      player:drawCards(1, hx__kongcheng_mu.name)
    end
    if right < 3 then
      room:doBroadcastNotify("ShowToast", "正确项小于3，此牌对"..Fk:translate(player.general).."无效")
      data.use.nullifiedTargets = data.use.nullifiedTargets or {}
      table.insertIfNeed(data.use.nullifiedTargets, player)
    end
  end,
})

return hx__kongcheng_mu